import { Filter,GlProgram} from "pixi.js";
import vertex from '@/filters/defaultFilter.vert?raw'
import fragment from '@/filters/Screen/Screen.frag?raw';
export class ScreenFilter extends Filter{
    constructor(){
        super({
            glProgram:new GlProgram({
                vertex,
                fragment
            }),
            resources:{
                localUniforms:{
                    tone:{
                        value:[0,0,0,0],
                        type:'vec4<f32>'
                    }
                }
            }
        });
    }
    get opacity(){
        return this.resources.localUniforms.uniforms.tone[3]*255;
    }
    set opacity(value){
        this.resources.localUniforms.uniforms.tone[3]=value/255;
    }

    getTone(){
        let tone=this.resources.localUniforms.uniforms.tone;
        return [tone[0]*255,tone[1]*255,tone[2]*255,tone[3]*255];
    }

    setTone(r=0,g=0,b=0,a=0){
        let tone=this.resources.localUniforms.uniforms.tone;
        tone[0]=r/255;
        tone[1]=g/255;
        tone[2]=b/255;
        tone[3]=a/255;
    }

    setAlpha(a){
        this.resources.localUniforms.uniforms.tone[3]=a/255;
    }
}